package org.example.controller;

import lombok.RequiredArgsConstructor;
import org.example.entity.Staff;
import org.example.service.StaffService;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.UUID;

@RestController
@RequestMapping("/staff")
@RequiredArgsConstructor
public class StaffController {

    private final StaffService service;

    @GetMapping("list")
    public List<Staff> list() {
        return service.list();
    }

    @GetMapping("listByName")
    public List<Staff> listByName(String name) {
        return service.list(name);
    }

    @GetMapping("listByAge")
    public List<Staff> listByAge(Integer age) {
        int a = 1/0;
        System.out.println(a);
        return service.list(age);
    }

    @PostMapping("add")
    public String add(@RequestBody Staff staff) {
        staff.setId(null);
        staff.setName(staff.getName() + "@" + new UUID(10, 5));
        service.add(staff);
        return "ok";
    }
}
